frontend/pages/e/[uuid]/index.tsx (view raw)
1import {PropsWithChildren} from 'react';
2import TravelColumns from '../../../containers/TravelColumns';
3import pageUtils from '../../../lib/pageUtils';
4import EventLayout from '../../../layouts/Event';
5import {EventByUuidDocument} from '../../../generated/graphql';
6import {getLocaleForLang} from '../../../lib/getLocale';
7import {getSession} from 'next-auth/react';
8
9interface Props {
10 eventUUID: string;
11 announcement?: string;
12}
13
14const Page = (props: PropsWithChildren<Props>) => {
15 return <EventLayout {...props} Tab={TravelColumns} />;
16};
17
18export const getServerSideProps = pageUtils.getServerSideProps(
19 async (context, apolloClient) => {
20 const {uuid} = context.query;
21 const {host = ''} = context.req.headers;
22 const session = await getSession(context);
23 let event = null;
24
25 const userHasNotAcceptedTos =
26 !!session?.profile && !session.profile.tosAcceptationDate;
27 if (userHasNotAcceptedTos)
28 return {
29 redirect: {
30 destination: '/auth/confirm',
31 permanent: false,
32 },
33 };
34
35 // Fetch event
36 try {
37 const {data} = await apolloClient.query({
38 query: EventByUuidDocument,
39 variables: {uuid},
40 });
41 event = data?.eventByUUID?.data;
42 } catch (error) {
43 return {
44 notFound: true,
45 };
46 }
47
48 const description = await getLocaleForLang(
49 event?.attributes?.lang,
50 'meta.description'
51 );
52
53 return {
54 props: {
55 eventUUID: uuid,
56 metas: {
57 title: event?.attributes?.name || '',
58 description,
59 url: `https://${host}${context.resolvedUrl}`,
60 },
61 },
62 };
63 }
64);
65
66export default Page;